/* GUI CONVERTED from gpsiver.p (converter v1.75) Sun Aug 13 18:35:44 2000 */
/* gpsiver.p - PROCEDURE TO VALIDATE SITES FOR DATA ENTRY                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                        */
/*M02W*/ /*V8:WebEnabled=No                                             */
/* REVISION:  7.5     LAST MODIFIED: 09/28/94    BY:  MWD  *J034*            */
/* REVISION: 9.0      LAST MODIFIED: 12/22/98   BY: *M02W* Luke Pokic   */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KS* myb               */
/*                                                                           */
/*****************************************************************************/
/* This subroutine determines whether a particular user is allowed to        */
/* enter data for a given site, based on his assigned user groups            */
/* It looks up the si_mstr based on either the si_recid (if available) or    */
/* the site.  If the si_mstr is found and has security assigned, compares    */
/* to see if any of the user's groups is among the security groups           */
/* (si_canrun) for the site.  Returns a code of 1 for authorized, 0 for NOT  */
/* authorized.  The calling program is expected to display any messages      */
/* and/or take other action based on that return code.                       */
/*                                                                           */
/* Called by icedit1.i and icedit2.i transaction edit routines as well as a  */
/* number of maintenance routines which get user data entry by site.         */
/*****************************************************************************/
/*  parameters used:                                                         */
/* input variables:        sisite                  input site                */
/*                         si_recno                recid of site being       */
/*                                                 processed                 */
/* output variable:        authorized              integer return code       */
/*                                                 1=authorized; 0-not auth  */
/*****************************************************************************/

{mfdeclre.i}       /* COMMON VARIABLES                  */
{mf1.i}            /* ADDITIONAL COMMON VARIABLES, SUCH */

/* AS GLOBAL_USER_GROUPS             */

define output parameter site_list  as character init "".
define variable authorized as integer init 1.
define variable group_indx          as integer.

/* CHECK SITE FOR USER GROUP AUTHORIZATION */
for each si_mstr no-lock :

	if si_canrun <> "" then do:
	
		authorized = 0.
		
		if can-do (si_canrun + ",!*",global_userid) then do:
			if site_list = "" then
				site_list = si_site.
			else		
			    site_list = site_list + "," + si_site.
		end.	

		if authorized = 0 then do:
			do group_indx = 1 to num-entries(global_user_groups) while authorized = 0:
				if can-do (si_canrun + ",!*", entry(group_indx, global_user_groups) ) then do:
					if site_list = "" then
						site_list = si_site.
					else		
			    		site_list = site_list + "," + si_site.
				end.
			end.  /* DO WHILE */
		end.
	end.  /* (if ...) */
	else do:
		if site_list = "" then
			site_list = si_site.
		else		
		    site_list = site_list + "," + si_site.
	end.
end.
